using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Unibot
{
    class Timer
    {
        TimeSpan initialtime;
        TimeSpan lastelapsedtime;
        GraphicsDevice graphics;

        public Timer(TimeSpan time, GraphicsDevice g)
        {
            initialtime = time;
            graphics = g;
        }

        public void ResetTimer(TimeSpan time)
        {
            initialtime = time;
        }

        //returns the elapsed time in milleseconds
        public TimeSpan ElapsedTime(TimeSpan time)
        {
            return time.Subtract(initialtime);
        }

        public void Update(TimeSpan time)
        {
            lastelapsedtime = ElapsedTime(time);
        }

        public void Draw()
        {
            SpriteBatch sb = new SpriteBatch(graphics);
            sb.Begin(SpriteBlendMode.AlphaBlend);
            
            string todisplay = lastelapsedtime.TotalMinutes.ToString("00") 
                               + ":" + lastelapsedtime.Seconds.ToString("00") 
                               + ":"  + lastelapsedtime.Milliseconds.ToString("000") ;
            Vector2 drawat = new Vector2(50, 50);

            sb.DrawString(Fonts.forte, todisplay, drawat, Color.OrangeRed);
            sb.End();

        }
    }
}
